// https://leetcode.cn/problems/combinations/submissions/

class Solution {
public:
    void dfs(vector<vector<int>>& res, vector<int>& tmp, int start, int end, int k) {
        if (tmp.size() == k) {
            res.push_back(tmp);
        }
        for (int i = start; i <= end; ++i) {
            tmp.push_back(i);
            dfs(res, tmp, i + 1, end, k); // 和排列区别：是i+1而不是start+1
            tmp.pop_back();
        }
    }
    vector<vector<int>> combine(int n, int k) {
        vector<vector<int>> res;
        vector<int> tmp;
        dfs(res, tmp, 1, n, k);
        return res;
    }
};